package org.hibernate.cfg;

import java.util.Properties;

import org.hibernate.cfg.reveng.JDBCReader;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.dialect.MetaDataDialect;
import org.hibernate.dialect.Dialect;

final public class JDBCReaderFactory {
	
	/**
	 * 创建MetaDataDialect
	 * 
	 * @param cfg 是指HibernateTool的配置信息，主要指hibernatetool.metadatadialect属性；
	 * @param settings Settings
	 * @param revengStrategy ReverseEngineeringStrategy
	 * @return MetaDataDialect
	 */
	public static JDBCReader newJDBCReader(Properties cfg, Settings settings, ReverseEngineeringStrategy revengStrategy) {
		MetaDataDialect mdd = newMetaDataDialect( settings.getDialect(), cfg );
		return newJDBCReader( settings, revengStrategy, mdd );
	}

	/**
	 * 创建MetaDataDialect
	 * 
	 * @param settings Settings
	 * @param revengStrategy ReverseEngineeringStrategy
	 * @param mdd MetaDataDialect
	 * @return MetaDataDialect
	 */
	public static JDBCReader newJDBCReader(Settings settings, ReverseEngineeringStrategy revengStrategy, MetaDataDialect mdd) {
		return new JDBCReader( mdd, settings.getConnectionProvider(), settings.getSQLExceptionConverter(), 
				settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), revengStrategy );
	}

	/**
	 * 创建MetaDataDialect
	 * 
	 * @param dialect Hibernate方言
	 * @param cfg 是指HibernateTool的配置信息，主要指hibernatetool.metadatadialect属性；
	 * @return MetaDataDialect
	 */
	public static MetaDataDialect newMetaDataDialect(Dialect dialect, Properties cfg) {
		return MetaDataDialectFactory.createMetaDataDialect(dialect, cfg);		
	}
	
}
